package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.Camp;
import com.ruoyi.wechat.service.ICampService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("wechat/camp")
public class WxCampController extends BaseController {
    @Autowired
    private ICampService campService;
    /**
     * 查询营地管理列表
     */
    @ApiOperation("营地列表")
    @GetMapping("/wxlist")
    public TableDataInfo list(Camp camp)
    {
        startPage();
        List<Camp> list = campService.selectCampList(camp);
        return getDataTable(list);
    }
    /**
     * 新增营地管理
     */
//    @PreAuthorize("@ss.hasPermi('camp:camp:add')")
//    @Log(title = "营地管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Camp camp){
        return success(campService.insertCamp(camp));
    }
    /**
     * 修改营地管理
     */
    @PutMapping("update")
    public AjaxResult edit(@RequestBody Camp camp){
        return toAjax(campService.updateCamp(camp));
    }
    /**
     * 获取营地管理详细信息
     */
    @GetMapping(value = "/get/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId){
//        return success(campService.selectCampByCampId(campId));
        //调用查询营地详情，并记录点击量的方法
        return success(campService.wxselectCampByCampId(campId));
    }
    /**
     * 删除营地管理
     */
    @DeleteMapping("/delete/{campIds}")
    public AjaxResult remove(@PathVariable String[] campIds){
        return toAjax(campService.deleteCampByCampIds(campIds));
    }

    /**
     * 查询营地 排序 列表
     */
    @ApiOperation("营地排序列表")
    @GetMapping("/sort")
    public TableDataInfo sort(Camp camp)
    {
        //获取排序列表
        List<Camp> list = campService.wxselectCampList(camp);
        return getDataTable(list);
    }
}
